package main

import (
	"encoding/json"
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
)

func AskInfo(c *gin.Context) {

	err, re := AskDonateInfo(c.Param("id"))
	if err != nil {
		log.Println(err)
		c.String(503, "%s", "inside error")
	}
	fmt.Println(re)
	jre, err := json.Marshal(re)
	if err != nil {
		log.Println(err)
		c.String(503, "%s", "inside error")
	}
	res := fmt.Sprintf("%s", jre)
	c.String(200, "%s", res)
}

func AddInfo(c *gin.Context) {
	var InfoPara struct {
		Id string `json:"id"`
		Username string `json:"username"`
		Money string `json:"money"`
		Addr string `json:"addr"`
	}
	if err := c.Bind(&InfoPara); err != nil {
		log.Println(err)
		c.String(503, "%s", "error")
		return
	}
	err := AddDonateInfo(InfoPara.Id, InfoPara.Username, InfoPara.Money, InfoPara.Addr)
	if err != nil {
		c.String(403, "%s", "donate fail")
		return
	}
	err = AddDonateCount(InfoPara.Id, InfoPara.Money)
	if err != nil {
		c.String(403, "%s", "donate fail")
		return
	}
	c.String(200, "%s", "donate success")
}